@gradingform @gradingform_metaagm
Feature: Metacriteria can be created and deleted
  In order to use a few AGM's at one grading form
  As a teacher
  I need to create at least one metacriterion

  Background:
    Given the following "users" exist:
      | username | firstname | lastname | email            |
      | teacher1 | Teacher   | 1        | teacher1@asd.com |
    And the following "courses" exist:
      | fullname | shortname | format |
      | Course 1 | C1        | topics |
    And the following "course enrolments" exist:
      | user     | course | role           |
      | teacher1 | C1     | editingteacher |
    And I log in as "teacher1"
    And I follow "Course 1"
    And I turn editing mode on
    And I add a "Assignment" to section "1" and I fill the form with:
      | Assignment name | Test assignment 1 name      |
      | Description     | Test assignment description |
      | Grading method  | Meta AGM                    |

  Scenario: Add first metacriterion
    When I go to "Test assignment 1 name" advanced grading definition page
    And I create the metacriterion "Test metacriterion 1" with grade weight "1.0" and grading method "Marking guide"
    Then I should see "Test metacriterion 1"

  Scenario: Add two metacriteria
    When I go to "Test assignment 1 name" advanced grading definition page
    And I create the metacriterion "Test metacriterion 1" with grade weight "1.0" and grading method "Marking guide"
    And I create the metacriterion "Test metacriterion 2" with grade weight "2.0" and grading method "Rubric"
    Then I should see "Test metacriterion 1"
    And I should see "Test metacriterion 2"
    
  Scenario: Delete metacriteria
    When I go to "Test assignment 1 name" advanced grading definition page
    And I create the metacriterion "Test metacriterion 1" with grade weight "1.0" and grading method "Marking guide"
    And I create the metacriterion "Test metacriterion 2" with grade weight "2.0" and grading method "Rubric"
    Then I should see "Test metacriterion 1"
    And I should see "Test metacriterion 2"
    When I delete metacriterion "Test metacriterion 1"
    And I delete metacriterion "Test metacriterion 2"
    Then I should not see "Test metacriterion 1"
    And I should not see "Test metacriterion 2"

  Scenario: Rename metacriterion
    When I go to "Test assignment 1 name" advanced grading definition page
    And I create the metacriterion "Test metacriterion 1" with grade weight "1.0" and grading method "Marking guide"
    Then I should see "Test metacriterion 1"
    When I rename metacriterion "Test metacriterion 1" to "Test metacriterion renamed"
    Then I should not see "Test metacriterion 1"
    And I should see "Test metacriterion renamed"

  Scenario: Change metacriterion grade weight
    When I go to "Test assignment 1 name" advanced grading definition page
    And I create the metacriterion "Test metacriterion 1" with grade weight "1.0" and grading method "Marking guide"
    Then I should see "Test metacriterion 1"
    When I change grade weight of metacriteria "Test metacriterion 1" to "56.729"
    # We use 'I should see' because the 'field matches' doesn't look for static fields.
    Then I should see "56.729"